import * as childProcess from 'node:child_process';
import * as os from 'node:os';
import * as path from 'node:path';
import * as util from 'node:util';

const execPromise = util.promisify(childProcess.exec);

export async function killChrome() {
  try {
    const { stdout, stderr } = await execPromise('taskkill /IM chrome.exe /F');
    if (stderr) {
      console.error(`killChrome 错误输出: ${stderr}`);
      return;
    }
    // console.log(`输出结果: ${stdout}`);
  } catch (error) {
    console.error(`killChrome 执行出错: ${error.message}`);
  }
}

export const checkIsMac = () => os.platform() === 'darwin';

export const fullScreenChrome = () => {
  const activeAhkScriptPath = path.join(process.cwd(), 'scripts/active.ahk');

  try {
    // 同步执行命令
    childProcess.execSync(activeAhkScriptPath);
  } catch (error) {
    console.error(`执行chrome全屏出错: ${error}`);
  }
};
